import com.troyworks.hsmf.AEvent;
import com.troyworks.hsmf.Hsmf;
import com.troyworks.hsmf.Signal;
import com.troyworks.hsmf.test.ILightSwitch;

/**
 * Illustrates a basic statemachine consisting of 2 states (on and off) and one event that toggles between them.
 * 
 * ON <=====TOGGLE ===>OFF
 *
 * On state is expected 2 movie clips
 * light_mc: unknown, on, off
 * toggle_mc: 
 * 
 * 
 * @author Troy Gardner
 */
class com.troyworks.hsmf.test.BasicLightSwitch extends Hsmf implements ILightSwitch {
	public static var TOGGLE_SIG : Signal = new Signal (USER_SIG.value + 0, "ROGGLE_SIG");
	private var timeline:MovieClip;
	public var light_mc:MovieClip;
	public var toggle_mc:MovieClip;
	function BasicLightSwitch (tl : MovieClip)
	{
		super ();
		Q_INIT(this.s1_off);
		trace("BasicLightSwitch " +  this.light_mc);
		timeline = tl;
		this.toggle_mc.onRelease =this.createCallback(new AEvent(BasicLightSwitch.TOGGLE_SIG));
		this.init(null);
	}	
	public function s1_on(e : AEvent) : Function {


		var sn = "s1-on";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{   trace("on");
				this.light_mc.gotoAndStop ("on");
				return null;
			}
			case EXIT_EVT :
			{
				trace("leaving on");
				this.light_mc.gotoAndStop ("unknown");
				return null;
			}

			case TOGGLE_SIG :
			{
				this.Q_TRAN (this.s1_off);
				return null;
			}
		}
		return s_top;
	}

	public function s1_off(e : AEvent) : Function {

		
		var sn = "s1-off";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{	trace("off");
				this.light_mc.gotoAndStop ("off");
				return null;
			}
			case EXIT_EVT :
			{
				trace("leaving off");
				this.light_mc.gotoAndStop ("unknown");
				return null;
			}

			case TOGGLE_SIG :
			{
				this.Q_TRAN (this.s1_on);
				return null;
			}
		}
		return s_top;
	}

}